import monocle.Iso
import monocle.macros.{GenIso, GenLens}

object TestMonocle extends App {


  case class T(name: String, age: Int)


  val t = GenLens[T] {
    _.age
  }

  t.asSetter

  case class Person(name: String, age: Int, address: Address=null)

  val personToTuple = Iso[Person, (String, Int)](p =>
    (p.name, p.age)) { case (name, age) => Person(name, age) }
  val t1 = personToTuple("111", 1)


  println(personToTuple.get(t1))

  case class MyString(s: String)

  println(GenIso[MyString, (String)].get(MyString("1112")))


  println(GenIso.fields[Person].get(t1))


  case class Address(strNumber: Int, streetName: String)

  val streetNumber = GenLens[Address](_.strNumber)

  val address = Address(10, "High Street")
  streetNumber.get(address)
  val addr= streetNumber.set(5)(address)

  println(address)

  println(addr)


  def neighbors(n: Int): List[Int] =
    if (n > 0) List(n - 1, n + 1) else List(n + 1)

  import scalaz.std.list._
  streetNumber.modifyF(neighbors)(address)
  val rr= streetNumber.modifyF(neighbors)(Address(135, "High Street"))
println(rr)


  val john = Person("John", 20, address)

  val addressLens = GenLens[Person](_.address)

  val com=addressLens composeLens streetNumber



}
